<?php
class NewsAdminCatsForm extends Form
{
	function __construct()
	{				
		Form::Form('NewsAdminCatsForm');
	}
	
	function draw()
	{
		global $display;
		
		$cats	=	array();	
		
		$display->add('url_add',Url::build_current(array('cmd'=>'add')));
		
		/*
		$display->add('url_edit',Url::build_current(array('cmd'=>'edit','id'=>$category['id'])));
		$display->add('url_del',Url::build_current(array('cmd'=>'delete','id'=>$category['id'])));
		$display->add('url_sort_up',Url::build_current(array('cmd'=>'move_home','dir'=>'move_home','id'=>$category['id'])));
		$display->add('url_sort_low',Url::build_current(array('cmd'=>'move_home','dir'=>'move_end','id'=>$category['id'])));
		*/
		
		$posMin	=	1;
		$posMax	=	DB::count("news_categories");
		
		$re = DB::query('SELECT * FROM news_categories ORDER BY position, id');
		if($re)
		{
			$index	=	0;
			$column = 	1;
			
			while ($row = mysql_fetch_assoc($re))
			{
				$row['url']   = URL::build('news_list',array('news_catid'=>$row['id'],'azname'=>AZLib::safe_title($row['name'])));
				
				$row['edit']   = Url::build_current(array('cmd'=>'edit','id'=>$row['id']));
				$row['delete'] = Url::build_current(array('cmd'=>'delete','id'=>$row['id']));
				
				$row['move_home'] 	= '<a title="Chuyển lên trên cùng" href="'.Url::build_current(array('cmd'=>'move_home','id'=>$row['id'])).'">Move HOME</a>';
				
				$row['move_end'] 	= '<a title="Chuyển xuống dưới cùng" href="'.Url::build_current(array('cmd'=>'move_end','id'=>$row['id'])).'">Move END</a>';
				
				if($row['position']>$posMin)
					$row['move_up'] = '<a title="Chuyển lên" href="'.Url::build_current(array('cmd'=>'move_up','id'=>$row['id'])).'"><img src="style/img/admin/move_up.gif"></a>';

				if($row['position']<$posMax)
					$row['move_down'] = '<a title="Chuyển xuống" href="'.Url::build_current(array('cmd'=>'move_down','id'=>$row['id'])).'"><img src="style/img/admin/move_down.gif"></a>';

				$cats[$row['id']] = $row;
			}
		}
		
		$display->add('cats',$cats);
		
		$display->output("NewsAdminCats");
	}
}
?>